View Javadoc

1   // Code2CodeReference.java, created Thu Mar  6 22:18:34 2003 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.Assembler;
5   
6   import java.io.DataOutput;
7   import java.io.IOException;
8   import joeq.Allocator.DefaultCodeAllocator;
9   import joeq.Memory.CodeAddress;
10  
11  /***
12   * Code2CodeReference
13   *
14   * @author  John Whaley <jwhaley@alum.mit.edu>
15   * @version $Id: Code2CodeReference.java 1941 2004-09-30 03:37:06Z joewhaley $
16   */
17  public class Code2CodeReference extends Reloc {
18  
19      private CodeAddress from_codeloc;
20      private CodeAddress to_codeloc;
21      
22      /*** Creates new Code2HeapReference */
23      public Code2CodeReference(CodeAddress from_codeloc, CodeAddress to_codeloc) {
24          this.from_codeloc = from_codeloc; this.to_codeloc = to_codeloc;
25      }
26  
27      public CodeAddress getFrom() { return from_codeloc; }
28      public CodeAddress getTo() { return to_codeloc; }
29      
30      public void patch() {
31          // hack: don't patch empty code references.
32          if (to_codeloc != null)
33              DefaultCodeAllocator.patchAbsolute(from_codeloc, to_codeloc);
34      }
35      
36      public void dumpCOFF(DataOutput out) throws IOException {
37          out.writeInt(from_codeloc.to32BitValue()); // r_vaddr
38          out.writeInt(0);                           // r_symndx
39          out.writeChar(Reloc.RELOC_ADDR32);         // r_type
40      }
41      
42      public String toString() {
43          return "from code:"+from_codeloc.stringRep()+" to code:"+to_codeloc.stringRep();
44      }
45      
46  }